package acom.dhy.qigsaw2test

import acom.dhy.qigsaw2test.qigsaw.QigsawConfig
import acom.dhy.qigsaw2test.qigsaw.loadSplashFragmentUpgraded
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.dhy.compatbundle.defaultQigsawSplitVersionFile
import com.dhy.qigsaw.splash.ISplashFragment
import org.jetbrains.annotations.TestOnly

/**
 * 当前启动模式为：先安装或更新所有模块，再启动应用。
 * 如果想按需加载，修改为启动 MainActivity 即可。
 * */
class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
//        initTestSplitUpdate()
        val splashFragment: ISplashFragment = loadSplashFragmentUpgraded(classLoader) ?: SplashFragment()
        splashFragment.startSplash(this, QigsawConfig.DYNAMIC_FEATURES.toList(), R.id.splash_activity_root_layout)
    }

    @TestOnly
    private fun initTestSplitUpdate() {
        val file = defaultQigsawSplitVersionFile
        if (!file.exists()) {
            assets.open("d31cad8b9b93fdc0ca2d92ab9f0c47ea.json").use {
                file.createNewFile()
                file.writeBytes(it.readBytes())
            }
        }
    }
}